
# 文件读写

def test1():
    file = open('../test.txt', 'r') # 打开一个文件
    str = file.readline() # 读第一行
    # print(str.strip())
    print(str) # 打印出第二行的内容
    str = file.readline()
    print(str)

def test_passwd_read():
    file = open('../passwds.txt', 'r') # 打开密码本
    str = file.readline() # 读第一行
    print(str)
    fields = str.split()
    print(fields)
    username = fields[1]
    passwd = fields[2]
    print(f'username={username}')
    print(f'passwd={passwd}')
    logon(username, passwd)

def read_all():
    file = open('../npm.txt', 'r')  # 打开密码本
    lines = file.readlines() # 读取所有行
    # print(lines)
    packages = []
    for line in lines:
        fields = line.split(':')
        packages.append(fields[0][1:-1])
        # print_user_passwd(line)
        # fields = line.split()
        # # print(fields)
        # username = fields[1]
        # passwd = fields[2]
        # print(f'username={username}')
        # print(f'passwd={passwd}')
    print(' '.join(packages))

def print_user_passwd(line):
    fields = line.split()
    # print(fields)
    username = fields[1]
    passwd = fields[2]
    print(f'username={username}')
    print(f'passwd={passwd}')

# 登录函数
def logon(username, passwd):
    pass

# test1()
# test_passwd_read()
read_all()